#pragma once

#include <memory>
#include <mutex>
#include "json.h"

class DeviceManager{
public:
    using Ptr = std::shared_ptr<DeviceManager>; 
    static Ptr Instance();
    DeviceManager();

    ~DeviceManager();

    void RegistRPC();
    void UpdateDeviceList();
    void EventUpdateDevice(std::string& product_name, std::string& product_model, std::string& phy_version, 
        std::string& soft_version, std::string& serial_number, const std::string& updateType);
    void UpdateUpgradeProgress(const std::string& serial_number, int progress);
private:

    bool GetAgentVersion(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo);
    bool StartAgentUpgrade(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo);

    bool GetDeviceList(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo);
    bool StartDeviceUpgrade(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo);
    bool StartDeviceReboot(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo);
    bool StartDeviceSystemReset(const Json::Value& req_params, Json::Value& res_result, std::string& errinfo);
    std::recursive_mutex m_mux;
    bool m_last_upgrading;
};